from google.appengine.api import users
from django.shortcuts import render_to_response

def respond(request, template, params=None):
    
    if params is None:
        params = {}

    if hasattr(request,'user'):
        params['user'] = request.user
        params['sign_out'] = users.CreateLogoutURL('/')
        params['is_admin'] = users.is_current_user_admin()
    else:
        params['sign_in'] = users.CreateLoginURL(request.path)

    #params['configuration'] = configuration

    if not template.endswith('.html'):
        template += '.html'

    return render_to_response(template, params)

def forbidden(request, error_message):
    response = respond(request, 'gtug/403.html', {'error_message': error_message})
    return response